package com.yexiao.cofe.consumer;

import com.yexiao.cofe.business.service.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
@Slf4j
public class DeadLetterQueueConsumer {

    @Resource
    private OrderService orderService;

    // 订单超时未支付
    @RabbitListener(queues = "deadletter.queue")
    public void receive(String orderId) {
        log.info("订单超时未支付， 开始处理, 订单号:{}", orderId);
        try{
            orderService.expire(orderId);
        } catch (Exception e) {
            log.info("订单超时未支付， 处理失败, 订单号:{}， 原因：{}", orderId, e.getMessage());
            e.printStackTrace();
        }
        log.info("订单超时未支付， 处理完成, 订单号:{}", orderId);
    }
}
